import request from '@/utils/request'
import type { AxiosResponse } from 'axios'

export interface UserInfo {
  nickName: string
  userName: string
  avatar: string
  // intro: string
  // registerType: number
  email: string
  // roles: string[]
  sex: number
  permissions: string[]
  createTime: string
}

// 登录
export function login(data: { username: string; password: string; remember: boolean }) {
  return request({
    url: '/login',
    method: 'post',
    headers: {
      isToken: false
    },
    data: data
  })
}

export function register(data: any) {
  return request({
    url: '/user/register',
    method: 'post',
    headers: {
      isToken: false
    },
    data
  })
}

export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

export function getUserInfo(): Promise<AxiosResponse<UserInfo>> {
  return request({
    url: '/user/userInfo',
    method: 'get'
  })
}

export function savaUserInfo(userinfo: any) {
  return request({
    url: '/user/userInfo',
    method: 'put',
    data: userinfo
  })
}
